<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>举个例子 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/lowercase-token-filter.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/lowercase-token-filter.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/lowercase-token-filter.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/lowercase-token-filter.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="languages.html">处理人类语言</a></span>
»
<span class="breadcrumb-link"><a href="token-normalization.html">归一化词元</a></span>
»
<span class="breadcrumb-node">举个例子</span>
</div>
<div class="navheader">
<span class="prev">
<a href="token-normalization.html">« 归一化词元</a>
</span>
<span class="next">
<a href="asciifolding-token-filter.html">如果有口音 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="lowercase-token-filter"></a>举个例子<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/220_Token_normalization/10_Lowercasing.asciidoc">edit</a>
</h2>
</div></div></div>
<p>用的最多的语汇单元过滤器(token filters)是 <code class="literal">lowercase</code> 过滤器，它的功能正和你期望的一样；它将每个词元(token)转换为小写形式：</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">GET /_analyze?tokenizer=standard&amp;filters=lowercase
The QUICK Brown FOX! <a id="CO138-1"></a><i class="conum" data-value="1"></i></pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO138-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>得到的词元(token)是 <code class="literal">the</code>, <code class="literal">quick</code>, <code class="literal">brown</code>, <code class="literal">fox</code></p>
</td>
</tr>
</table>
</div>
<p>只要查询和检索的分析过程是一样的，不管用户搜索 <code class="literal">fox</code> 还是 <code class="literal">FOX</code> 都能得到一样的搜索结果。<code class="literal">lowercase</code> 过滤器会将查询 <code class="literal">FOX</code> 的请求转换为查询 <code class="literal">fox</code> 的请求， <code class="literal">fox</code> 和我们在倒排索引中存储的是同一个词元(token)。</p>
<p>为了在分析过程中使用 token 过滤器，我们可以创建一个 <code class="literal">custom</code> 分析器：</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">PUT /my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_lowercaser": {
          "tokenizer": "standard",
          "filter":  [ "lowercase" ]
        }
      }
    }
  }
}</pre>
</div>
<p>我们可以通过 <code class="literal">analyze</code> API 来验证:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">GET /my_index/_analyze?analyzer=my_lowercaser
The QUICK Brown FOX! <a id="CO139-1"></a><i class="conum" data-value="1"></i></pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO139-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>得到的词元是 <code class="literal">the</code>, <code class="literal">quick</code>, <code class="literal">brown</code>, <code class="literal">fox</code></p>
</td>
</tr>
</table>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="token-normalization.html">« 归一化词元</a>
</span>
<span class="next">
<a href="asciifolding-token-filter.html">如果有口音 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>